<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name', 150)->nullable()->comment('用户名');
            $table->string('phone', 20)->unique()->nullable()->comment('手机号');
            $table->string('open_id', 150)->unique()->nullable()->comment('微信open_id');
            $table->string('unionid', 150)->unique()->nullable()->comment('微信unionid');
            $table->string('password', 150)->nullable()->comment('密码');
            $table->string('avatar', 150)->nullable()->comment('用户头像');
            $table->dateTime('last_login')->nullable()->comment('最后登录时间');
            $table->string('last_ip', 128)->nullable()->comment('最后登录IP');
            $table->tinyInteger('status')->unsigned()->default(1)->comment('账号状态 1:正常 2:禁止登陆');
            $table->string('nick_name', 50)->nullable()->comment('昵称');
            $table->enum('sex', [1, 2, 3])->default(3)->comment('性别：1-男，2-女，3-保密');
            $table->string('linkman', 50)->nullable()->comment('紧急联系人');
            $table->char('linkphone', 11)->nullable()->comment('紧急联系人手机');
            $table->bigInteger('company_id')->nullable()->index()->comment('公司ID');
            $table->string('address')->nullable()->comment('现住地址');
            $table->enum('source', [1, 2])->default(1)->comment('来源：1-自然流量，2-导入');
            $table->string('identity', 30)->nullable()->comment('身份证号码');
            $table->json('identity_photo')->nullable()->comment('身份证照片');
            $table->decimal('balance', 10, 2)->default(0)->comment('余额');
            $table->string('token', 50)->nullable()->comment('用户唯一token');
            $table->timestamps();
            $table->softDeletes();
        });

        DB::statement("ALTER TABLE `users` comment '用户表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
